/*
 * @(#)User.java   09/12/30
 * 
 * Copyright (C) 2009 Ecole des Mines d'Ales
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Contact: yulinz88@gmail.com
 */



package Example.Components;

import Example.Interfaces.AccountOprs;
import Example.Interfaces.UQuery;
import Example.Interfaces.USave;

import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.api.control.BindingController;
import org.objectweb.fractal.api.control.IllegalBindingException;
import org.objectweb.fractal.api.control.IllegalLifeCycleException;

//~--- classes ----------------------------------------------------------------

/**
 * Class description
 *
 *
 * @version        1.0, 09/12/30
 * @author         Huaxi (Yulin) ZHANG    
 */
public class User implements AccountOprs, BindingController {

    /** Field description */
    private UQuery UQuery;

    /** Field description */
    private USave USave;

    /**
     * Method description
     *
     * @param userID  
     * @return  
     */
    public double checkBalance(int userID) {

        // TODO Auto-generated method stub
        return 0.0;
    }

    /**
     * Method description
     *
     * @param userID  
     * @param userPassword  
     * @return  
     */
    public Object[] checkID(int userID, String userPassword) {
        System.out.println("user");

        return UQuery.findAccount(userID, userPassword);
    }

    /**
     * Method description
     *
     * @param userID  
     * @param cost  
     * @return  
     */
    public double debit(int userID, double cost) {

        // TODO Auto-generated method stub
        return 0.0;
    }

    /**
     * Method description
     *
     * @param cItf  
     * @param sItf  
     * @throws IllegalBindingException  
     * @throws IllegalLifeCycleException  
     * @throws NoSuchInterfaceException  
     */
    public void bindFc(String cItf, Object sItf)
            throws NoSuchInterfaceException, IllegalBindingException, IllegalLifeCycleException {
        if (cItf.equals("UQuery")) {
            UQuery = (UQuery) sItf;
        }

        if (cItf.equals("USave")) {
            USave = (USave) sItf;
        }
    }

    /**
     * Method description
     *
     * @return  
     */
    public String[] listFc() {
        return new String[] { "UQuery", "USave" };
    }

    /**
     * Method description
     *
     * @param cItf  
     * @return  
     * @throws NoSuchInterfaceException  
     */
    public Object lookupFc(String cItf) throws NoSuchInterfaceException {
        if (cItf.equals("UQuery")) {
            return UQuery;
        }

        if (cItf.equals("USave")) {
            return USave;
        }

        return null;
    }

    /**
     * Method description
     *
     * @param cItf  
     * @throws IllegalBindingException  
     * @throws IllegalLifeCycleException  
     * @throws NoSuchInterfaceException  
     */
    public void unbindFc(String cItf)
            throws NoSuchInterfaceException, IllegalBindingException, IllegalLifeCycleException {
        if (cItf.equals("UQuery")) {
            UQuery = null;
        }

        if (cItf.equals("USave")) {
            USave = null;
        }
    }
}
